package com.example.managemyself.util;

import android.content.Context;
import android.os.Build;

import androidx.appcompat.app.AppCompatDelegate;

/**
 * 主题帮助类，用于管理应用主题
 */
public class ThemeHelper {
    
    public static final String THEME_LIGHT = "light";
    public static final String THEME_DARK = "dark";
    public static final String THEME_SYSTEM = "system";
    
    /**
     * 应用主题
     * @param theme 主题名称：light, dark, system
     */
    public static void applyTheme(String theme) {
        switch (theme) {
            case THEME_LIGHT:
                AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                break;
            case THEME_DARK:
                AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                break;
            case THEME_SYSTEM:
            default:
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
                } else {
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
                }
                break;
        }
    }
    
    /**
     * 获取当前主题模式
     * @return 当前主题模式的描述字符串
     */
    public static String getCurrentThemeDescription(Context context) {
        int currentNightMode = AppCompatDelegate.getDefaultNightMode();
        switch (currentNightMode) {
            case AppCompatDelegate.MODE_NIGHT_NO:
                return "浅色模式";
            case AppCompatDelegate.MODE_NIGHT_YES:
                return "深色模式";
            case AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM:
                return "跟随系统";
            case AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY:
                return "省电模式";
            default:
                return "未知模式";
        }
    }
} 